<template>
    <div>
        <h1>添加页面</h1>
        <table class="table table-bordered" border="1px">
            <tbody>
                <tr>
                    <td>用户信息</td>
                    <td>
                        <input type="text" v-model="info.Username">
                    </td>
                </tr>
                <tr>
                    <td>门店信息</td>
                    <td>
                        <input type="text" v-model="info.HContext">
                    </td>
                </tr>
                <tr>
                    <td>应收款</td>
                    <td>
                        <input type="text" v-model="info.HPrice">
                    </td>
                </tr>
                <tr>
                    <td>实收款</td>
                    <td>
                        <input type="text" v-model="info.SPrice">
                    </td>
                </tr>
                <tr>
                    <td>现金收银信息</td>
                    <td>
                        <input type="text" v-model="info.Content">
                    </td>
                </tr>
                <tr>
                    <td>门店状态</td>
                    <td>
                        <input type="radio" v-model="info.State" :value="true"> 营业
                        <input type="radio" v-model="info.State" :value="false"> 闭店
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <button value="提交" class="btn btn-primary" @click="ok">提交</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router'
const router = useRouter();

let info: any = reactive({
    "Username": "",
    "HContext": "",
    "HPrice": '',
    "SPrice": '',
    "Content": "",
    "State": true
})

const ok = () => {
    if (info.Username == "") {
        alert('用户信息不能为空!');
        return;
    }
    if (info.HContext == "") {
        alert('门店信息不能为空!');
        return;
    }
    if (info.HPrice == "") {
        alert('应收款不能为空!');
        return;
    }
    if (info.SPrice == "") {
        alert('实收款不能为空!');
        return;
    }
    if (info.Content == "") {
        alert('现金收银信息不能为空!');
        return;
    }
    axios({
        url: 'https://localhost:7056/api/Hotel/add',
        method: 'post',
        data: info
    })
        .then((res) => {
            if (res.data > 0) {
                alert('添加成功！');
                router.push('/show');
                return;
            }
            else {
                alert('添加失败!');
                return;
            }
        })
}

</script>

<style scoped></style>